/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.google.common.collect.Maps;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Group;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import com.zimbra.soap.admin.type.CountObjectsType;
/*     */ import java.util.Map;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestLdapProvCountObjects
/*     */   extends LdapTest
/*     */ {
/*     */   private static LdapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  46 */     provUtil = new LdapProvTestUtil();
/*  47 */     prov = provUtil.getProv();
/*  48 */     domain = provUtil.createDomain(baseDomainName());
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  53 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void countAccount() throws Exception
/*     */   {
/*  59 */     Account userAcct = provUtil.createAccount(genAcctNameLocalPart("user"), domain);
/*  60 */     Account systemAcct = provUtil.createSystemAccount(genAcctNameLocalPart("system-acct"), domain);
/*     */     
/*     */ 
/*  63 */     Account systemResource = provUtil.createSystemResource(genAcctNameLocalPart("system-resource"), domain);
/*     */     
/*     */ 
/*  66 */     Account externalAccount = provUtil.createExternalAccount(genAcctNameLocalPart("external"), domain);
/*     */     
/*     */ 
/*  69 */     Map<String, Object> attrs = Maps.newHashMap();
/*  70 */     attrs.put("amavisArchiveQuarantineTo", "test@junk.com");
/*  71 */     Account archivingAcct = provUtil.createAccount(genAcctNameLocalPart("archiving"), domain, attrs);
/*     */     
/*  73 */     Domain otherDomain = provUtil.createDomain(genDomainName(domain.getName()));
/*  74 */     Account userAcctOtherDomain = provUtil.createAccount(genAcctNameLocalPart("user"), otherDomain);
/*     */     
/*  76 */     long num = prov.countObjects(CountObjectsType.userAccount, domain, null);
/*  77 */     Assert.assertEquals(4L, num);
/*     */     
/*  79 */     num = prov.countObjects(CountObjectsType.account, domain, null);
/*  80 */     Assert.assertEquals(5L, num);
/*     */     
/*  82 */     num = prov.countObjects(CountObjectsType.internalUserAccount, domain, null);
/*  83 */     Assert.assertEquals(3L, num);
/*     */     
/*  85 */     num = prov.countObjects(CountObjectsType.internalArchivingAccount, domain, null);
/*  86 */     Assert.assertEquals(1L, num);
/*     */     
/*  88 */     provUtil.deleteAccount(userAcct);
/*  89 */     provUtil.deleteAccount(systemAcct);
/*  90 */     provUtil.deleteAccount(systemResource);
/*  91 */     provUtil.deleteAccount(externalAccount);
/*  92 */     provUtil.deleteAccount(archivingAcct);
/*  93 */     provUtil.deleteAccount(userAcctOtherDomain);
/*  94 */     provUtil.deleteDomain(otherDomain);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void countAlias() throws Exception
/*     */   {
/* 100 */     Account acct = provUtil.createAccount(genAcctNameLocalPart("user"), domain);
/* 101 */     prov.addAlias(acct, TestUtil.getAddress(genAcctNameLocalPart("alias-1"), domain.getName()));
/* 102 */     prov.addAlias(acct, TestUtil.getAddress(genAcctNameLocalPart("alias-2"), domain.getName()));
/*     */     
/* 104 */     long num = prov.countObjects(CountObjectsType.alias, domain, null);
/* 105 */     Assert.assertEquals(2L, num);
/*     */     
/* 107 */     provUtil.deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void countDL() throws Exception {
/* 112 */     Group staticGroup = provUtil.createGroup(genGroupNameLocalPart("static"), domain, false);
/* 113 */     Group dynamicGroup = provUtil.createGroup(genGroupNameLocalPart("dynamic"), domain, true);
/*     */     
/* 115 */     Domain subDomain = provUtil.createDomain(genDomainName(domain.getName()));
/* 116 */     Group staticGroup1Sub = provUtil.createGroup(genGroupNameLocalPart("static-1"), subDomain, false);
/* 117 */     Group dynamicGroup1Sub = provUtil.createGroup(genGroupNameLocalPart("dynamic-1"), subDomain, true);
/* 118 */     Group staticGroup2Sub = provUtil.createGroup(genGroupNameLocalPart("static-2"), subDomain, false);
/* 119 */     Group dynamicGroup2Sub = provUtil.createGroup(genGroupNameLocalPart("dynamic-2"), subDomain, true);
/*     */     
/*     */ 
/*     */ 
/* 123 */     long num = prov.countObjects(CountObjectsType.dl, domain, null);
/* 124 */     Assert.assertEquals(2L, num);
/*     */     
/* 126 */     provUtil.deleteGroup(staticGroup);
/* 127 */     provUtil.deleteGroup(dynamicGroup);
/* 128 */     provUtil.deleteGroup(staticGroup1Sub);
/* 129 */     provUtil.deleteGroup(dynamicGroup1Sub);
/* 130 */     provUtil.deleteGroup(staticGroup2Sub);
/* 131 */     provUtil.deleteGroup(dynamicGroup2Sub);
/*     */     
/* 133 */     provUtil.deleteDomain(subDomain);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void countDomain() throws Exception
/*     */   {
/* 139 */     Domain subDomain = provUtil.createDomain(genDomainName(domain.getName()));
/* 140 */     Domain subSubDomain = provUtil.createDomain(genDomainName(subDomain.getName()));
/* 141 */     long num = prov.countObjects(CountObjectsType.domain, domain, null);
/*     */     
/*     */ 
/* 144 */     Assert.assertEquals(3L, num);
/*     */     
/*     */ 
/* 147 */     num = prov.countObjects(CountObjectsType.domain, null, null);
/*     */     
/*     */ 
/*     */ 
/* 151 */     Assert.assertEquals(5L, num);
/*     */     
/* 153 */     provUtil.deleteDomain(subSubDomain);
/* 154 */     provUtil.deleteDomain(subDomain);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void countCos() throws Exception {
/* 159 */     Cos cos = provUtil.createCos(genCosName());
/* 160 */     long num = prov.countObjects(CountObjectsType.cos, null, null);
/*     */     
/*     */ 
/*     */ 
/* 164 */     Assert.assertEquals(3L, num);
/*     */     
/* 166 */     provUtil.deleteCos(cos);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void countServer() throws Exception {
/* 171 */     Server server = provUtil.createServer(genServerName());
/* 172 */     long num = prov.countObjects(CountObjectsType.server, null, null);
/*     */     
/*     */ 
/*     */ 
/* 176 */     Assert.assertEquals(2L, num);
/*     */     
/* 178 */     provUtil.deleteServer(server);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestLdapProvCountObjects.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */